import { http } from '@/utils/http/axios';
export interface BasicResponseModel<T = any> {
  code: number;
  message: string;
  result: T;
}
export interface TokenResult<T = any> {
  access_token: string;
  token_type: string;
  refresh_token: string;
  expires_in:number;
  scope:number;
  roleIds:T;
  tenantId:number;
  deptId:number;
  userId:number;
  jti:string;
}
export interface BasicPageParams {
  pageNumber: number;
  pageSize: number;
  total: number;
}

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/userInfo',
    method: 'POST',
  });
}

/**
 * @description: 用户登录
 */
export function login(params) {
  return http.request<TokenResult>(
    {
      url: '/moss-cloud-auth/oauth/token',
      method: 'POST',
      params,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': 'Basic QzBDMzRERjc2ODMwRkE1MkU5NDk0NUY0QkMyMkUxRTg6MTE2OTNEQkNGM0JBQTE0OUI3MEE5QzY4QUFFRjQ5QTA=',
        'Cache-Control': 'no-cache'
      },
    },
    {
      isTransformResponse: false,
      withToken:false,
      isShowMessage:false
    }
  );
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params, uid) {
  return http.request(
    {
      url: `/user/u${uid}/changepw`,
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户登出
 */
export function logout<Result>() {
  return http.request({
    url: '/moss-cloud-auth/auth/auth/logout',
    method: 'POST',
    params:{},
  });
}

/**
 * @description: 用户列表
 */
export function usersPages(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/userPage',
    method: 'POST',
    data:params,
  });
}
/**
 * 租户部门树
 * @param params 
 * @returns 
 */
export function deptTree(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysDept/deptTree',
    method: 'POST',
    data:params,
  });
}
/**
 * 删除用户
 * @param params 
 * @returns 
 */
export function removeUser(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/removeUser',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}
/**
 * 添加用户
 * @param params 
 * @returns 
 */
export function adminAddUser(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/adminAddUser',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * 更新用户
 * @param params 
 * @returns 
 */
export function adminUpdUser(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/adminUpdUser',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * 租户信息
 * @param params 
 * @returns 
 */
export function tenantInfoByUserId(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysTenant/tenantInfoByUserId',
    method: 'POST',
    data:params,
  });
}

/**
 * 部门信息
 * @param params 
 * @returns 
 */
export function deptInfo(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysDept/deptInfo',
    method: 'POST',
    data:params,
  });
}

/**
 * 角色信息
 * @param params 
 * @returns 
 */
export function roleInfoByUserId(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUserRole/roleInfoByUserId',
    method: 'POST',
    data:params,
  });
}

/**
 * 用户角色授权
 * @param params 
 * @returns 
 */
export function saveBatchUserRole(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUserRole/saveBatchUserRole',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}
/**
 * 租户角色列表
 * @param params 
 * @returns 
 */
export function roleList(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysRole/roleList',
    method: 'POST',
    data:params,
  });
}

/**
 * 搜索用户
 * @param params 
 * @returns 
 */
export function searchUser(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/searchUser',
    method: 'POST',
    data:params,
  });
}
/**
 * 查询指定用户信息
 * @param params 
 * @returns 
 */
export function usersById(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/usersById',
    method: 'POST',
    data:params,
  });
}

/**
 * 重置用户密码
 * @param params 
 * @returns 
 */
export function resetPassword(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/resetPassword',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * 当前用户基本信息
 * @param params 
 * @returns 
 */
export function currentUser(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/currentUser',
    method: 'POST',
    data:params,
  });
}

/**
 * 用户修改信息
 * @param params 
 * @returns 
 */
export function updateSelf(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/updateSelf',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * 用户修改密码
 * @param params 
 * @returns 
 */
export function updatePassword(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/updatePassword',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * 锁定用户账号
 * @param params 
 * @returns 
 */
export function lockAccount(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/lockAccount',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * 解锁用户账号
 * @param params 
 * @returns 
 */
export function unlockAccount(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/unlockAccount',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}

/**
 * 账号锁定记录
 * @param params 
 * @returns 
 */
export function lockAccountRecordPage(params) {
  return http.request({
    url: '/moss-cloud-base/base/accountLockHistoryRecord/recordPage',
    method: 'POST',
    data:params,
  });
}

/**
 * 解锁用户账号
 * @param params 
 * @returns 
 */
export function userDepart(params) {
  return http.request({
    url: '/moss-cloud-base/base/sysUser/userDepart',
    method: 'POST',
    data:params,
  }, {
    isTransformResponse: false,
  });
}


